/**
 * 选择上传图片方式
 * @param {Object} options
 * @param {Object} callback
 * dst 剪裁后的 文件名
 */
function getImageWay(needCutImg,title,callback,dst){
	needCutImg = needCutImg?needCutImg:false;
	var bun = [{title: "拍照"}, {title: "从手机相册选择"}];
	plus.nativeUI.actionSheet({
		title: title,
		buttons: bun
	}, function(b) { /*actionSheet 按钮点击事件*/
		switch(b.index) {
			case 1:
				/*拍照*/
				chooseImgFromCamera(needCutImg,function(f) {
					callback?callback(f):'';
				},dst);
				break;
			case 2:
				/*打开相册*/
				chooseImgFromAlbums(needCutImg,function(f) {
					callback?callback(f):'';
				},dst);
				break;
			default:
				break;
		}
	})
}

/**
 * wangsh 20161123
 * 获取照片 上传
 * 
 */
//拍照
function chooseImgFromCamera(needCutImg,callback,dst) {
	var cmr = plus.camera.getCamera();
	cmr.captureImage(function(entry) {
		if(needCutImg){
			cutImg(entry,dst,function(f) {
				callback ? callback(f) : '';
			})
		}else{
			callback ? callback(entry) : '';
		}
	}, function(err) {
		console.log(JSON.stringify(err));
	}, {
		index: '2',
	});
}

//获得头像后跳转到剪裁页面
function chooseImgFromAlbums(needCutImg,callback,dst) {
	plus.gallery.pick(function(entry) {
		if(needCutImg){
			cutImg(entry,dst,function(f) {
				callback ? callback(f) : '';
			})
		}else{
			callback ? callback(entry) : '';
		}
	}, function(err) {
		console.log(JSON.stringify(err));
	}, {
		filter: 'image'
	});
}

//剪裁
function cutImg(path,dst,callback) {
	var option = {
		src: path,
		dst: dst,
		overwrite: true,
		format: 'jpg',
		quality: 100,
		width:'500px',
		height:'auto'/*,
		clip:{
			width: '500px',
			height:'500px'
		}*/
		
		
	}
	plus.zip.compressImage(option,
		function(entry) { //压缩成功
			//删除源文件
			plus.io.resolveLocalFileSystemURL(path,function(entry){
				entry.remove()
			})
			//执行回调
			callback ? callback(entry) : '';
		},
		function(error) {});
}